package com.twohand.admin.Service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.twohand.admin.Dto.WxRefundListQueryDto;
import com.twohand.admin.Entity.WxRefund;
import com.twohand.admin.Mapper.WxRefundMapper;
import com.twohand.admin.Service.IWxRefundService;
import com.twohand.admin.Util.PageResponse;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.math.BigDecimal;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ASDW
 * @since 2024-06-30
 */
@Service
public class WxRefundServiceImpl  implements IWxRefundService {
    @Autowired
    WxRefundMapper wxRefundMapper;
    public PageResponse<WxRefund> getAllWxRefundList(WxRefundListQueryDto wxRefundListQueryDto){
        PageHelper.startPage(wxRefundListQueryDto.getPageNum(),wxRefundListQueryDto.getPageSize());
        LambdaQueryWrapper<WxRefund> lambdaqueryWrapper = new LambdaQueryWrapper<>();
        String refundNoValue = wxRefundListQueryDto.getRefundNo();
        if(refundNoValue != null && StringUtils.isNotEmpty(refundNoValue)){
            lambdaqueryWrapper.eq(WxRefund::getRefundNo,refundNoValue);
        }
        String payNoValue = wxRefundListQueryDto.getPayNo();
        if(payNoValue != null && StringUtils.isNotEmpty(payNoValue)){
            lambdaqueryWrapper.eq(WxRefund::getPayNo,payNoValue);
        }
        BigDecimal priceValue = wxRefundListQueryDto.getPrice();
        if(priceValue != null && StringUtils.isNotEmpty(String.valueOf(priceValue))){
            lambdaqueryWrapper.eq(WxRefund::getPrice,priceValue);
        }
        Integer statusValue = wxRefundListQueryDto.getStatus();
        if(statusValue != null && StringUtils.isNotEmpty(String.valueOf(statusValue))){
            lambdaqueryWrapper.eq(WxRefund::getStatus,statusValue);
        }
        lambdaqueryWrapper.orderByDesc(WxRefund::getSuccessTime);
        List<WxRefund> selectList = wxRefundMapper.selectList(lambdaqueryWrapper);
        PageInfo<WxRefund> pageInfo = new PageInfo<>(selectList);
        return new PageResponse<WxRefund>(pageInfo,selectList);
    }
    public WxRefund getWxRefundById(Integer id){
        return wxRefundMapper.selectById(id);
    }
    public Boolean insertWxRefund(WxRefund wxRefund){
        return wxRefundMapper.insert(wxRefund) > 0;
    }
    public Boolean updateWxRefund(WxRefund wxRefund){
        return wxRefundMapper.updateById(wxRefund) > 0;
    }
    public Boolean deleteWxRefundById(Integer id){
        return wxRefundMapper.deleteById(id) > 0;
    }
}
